package com.spring;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Set;

public class JedisList {

    public static void test1(Jedis jedis) {
        System.out.println("lpush 和 rpush , lpop 和 rpop 的使用");
        jedis.flushAll();

        jedis.lpush("key1","123","456","789");

        jedis.rpush("key1","987","654","321");

        List<String> value = jedis.lrange("key1", 0, -1);
        System.out.println(value);


        String key1 = jedis.lpop("key1");
        System.out.println(key1);

        key1 = jedis.rpop("key1");
        System.out.println(key1);

        value = jedis.lrange("key1", 0, -1);
        System.out.println(value);
    }

    public static void test2(Jedis jedis) {
        // 阻塞版
        System.out.println("blpop 和 brpop 的使用");
        jedis.flushAll();
        System.out.println(jedis.keys("*"));

        List<String> key = jedis.blpop(100, "key");
        System.out.println(key);
    }

    public static void test3(Jedis jedis) {
        System.out.println(" llen 的使用");
        jedis.flushAll();

        jedis.lpush("key1","123","456","789");

        jedis.rpop("key1");
        System.out.println(jedis.llen("key1"));
    }

    public static void main(String[] args) {
        JedisPool jedispool=new JedisPool("tcp://127.0.0.1:8888");

        try(Jedis jedis=jedispool.getResource()){
            jedis.auth("123456");
//            test1(jedis);
//            test2(jedis);
            test3(jedis);
        }
    }
}
